//
//  MCStatusTopView.swift
//  HXWeibo
//
//  Created by HX on 15/12/2.
//  Copyright © 2015年 HX. All rights reserved.
//

import UIKit

class MCStatusTopView: UIView
{
    // MARK: - 属性
    /// 微博模型
    var status: MCStatus?
        {
            didSet
            {
                if let profile_image_url = status?.user?.profile_image_url
                {
                    // 使用SDWebImage下载头像
                    iconView.sd_setImageWithURL(NSURL(string: profile_image_url), placeholderImage: UIImage(named: "avatar"))
                }
                //设置用户名称
                nameLabel.text = status?.user?.screen_name
                
                // 时间
                timeLabel.text = status?.created_at
                
                // 来源
                sourceLabel.text = status?.source
                
                // 设置认证图标,根据不同的数字来设置不同的图片
                verifiedImageView.image = status?.user?.verifiedImage
                
                // 会员等级
                mbrankImageView.image = status?.user?.mbrankImage
                
            }
        }
    
    required init?(coder aDecoder: NSCoder)
    {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect)
    {
        super.init(frame: frame)
        
        prepareUI()
        
    }
    
    // MARK: - 准备UI
    private func prepareUI()
    {
//        backgroundColor = UIColor.brownColor()
        // 添加子控件
        addSubview(separatorView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(mbrankImageView)
        addSubview(verifiedImageView)
        
        //添加约束
        /// 分割视图约束
        separatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.size.width, height: 10))
        
        // 用户头像
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: separatorView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: MCStatusCellMargin, y: MCStatusCellMargin))
        
        // 用户名称
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: MCStatusCellMargin, y: 0))
        
        // 会员图标
        mbrankImageView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: MCStatusCellMargin, y: 0))
        
        // 时间
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: MCStatusCellMargin, y: 0))
        
        // 来源
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint(x: MCStatusCellMargin, y: 0))
        
        // 认证图标
        verifiedImageView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
    }
    
    // MARK: - 懒加载
    /// 用户头像
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar"))
    
    /// 用户名称
    private lazy var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    
    /// 消息发送时间
    private lazy var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    
    /// 消息来源
    private lazy var sourceLabel: UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    
    /// 会员等级图标
    private lazy var mbrankImageView: UIImageView = UIImageView()
    
    /// 认证类型图标
    private lazy var verifiedImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
    /// 顶部的分割视图
    private lazy var separatorView: UIView =
    {
        let view = UIView()
        
        view.backgroundColor = UIColor(white: 0.9, alpha: 1)
        
        return view
    }()
}


































